//   Copyright [SkyOS] [mrblond@skyhack.com.ar]
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

#ifndef BOOTMANAGER_HPP_
#define BOOTMANAGER_HPP_

#include "type.hpp"

/**
 * Record of a module loaded by the
 * BootLoader
 */
typedef struct BootFileList
{
	uInt  startAddr;
	uInt  endAddr;
	char* modName;
	uInt  reserved;
}BootFileList;

/**
 * Record of the memory map list
 */
typedef struct BootMemoryList
{
	uInt  size;
	uLong baseAddr;
	uLong length;
	uInt  type;
}BootMemoryList;

/**
 * Record of the multiboot to pass it
 * on all platform
 */
typedef struct BootRecord
{
	uInt   flags;
	uInt   memLower;
	uInt   memUpper;
	uByte  bootPartition[3];
	uByte  bootDrive;
	char*  cmdLine;
	uInt   modCount;
	BootFileList* modList;
	uInt   symNum;
	uInt   symSize;
	uInt   symAddr;
	uInt   symReserved;
	uInt   mmapLength;
	BootMemoryList* mmapList;
}BootRecord;


/**
 * <br>BootManager</br> contiene toda la informacion
 * del booteo de nuestro sistema.
 *
 * @author mrblond@skyhack.com.ar
 */
class BootManager
{
public:
	/**
	 * lpBootStructure - Structure of the multiboot to parse
	 */
	BootManager(BootRecord* lpBootStructure);
	/**
	 * Release all allocated by the boot loader.
	 */
	~BootManager();
	/**
	 * @return All the memory reported by the boot loader
	 */
	inline uSizeT getTotalMemory() const {
		return bootRecord->memUpper;
	}
	/**
	 * @values 0 = Floppy, 1 = HardDrive, 2 = CD-Drive, 3 = USB, 4 = Network
	 * @return The Device that boot the os.
	 */
	inline uByte getBootDevice() const {
		return bootRecord->bootDrive;
	}
	/**
	 * szBuffer     - Buffer that will hold the command line.
	 * dwLength     - Length of the buffer.
	 * @return TRUE if there is a command line to parse
	 */
	uBool getCommandLine(puByte szBuffer, uShort dwLength) const;
	/**
	 * dwAddress     - Hold the address of the kernel.
	 * dwLength      - Hold the size of the kernel.
	 */
	void  getKernelAddr(puSizeT dwAddress, puSizeT dwLength) const;
protected:
	BootRecord* bootRecord;
};

#endif /* BOOTMANAGER_HPP_ */
